﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OnlineCourse.Model;
using OnlineCourse.Model.Entity;
using OnlineCourse.Services;
using OnlineCourse.Services.IServices;
using OnlineCourse.Services.Model;

namespace OnlineCourse.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class CouponsRecordController : ControllerBase
    {
        private CouponRecordService _home;
        public CouponsRecordController(ApplicationDbContext db)
        {
            _home = new CouponRecordService(db);
        }
        /// <summary>
        /// 添加优惠券记录清单
        /// </summary>
        /// <param name="CouponsId">券的ID</param>
        /// <param name="Source">来源</param>
        /// <param name="UserId">用户ID</param>
        /// <returns></returns>
        [HttpPost("Add")]
        public IActionResult Add(int num, int meg, Guid CouponsId, string Source, Guid UserId)
        {
            var a = _home.Add( num, out meg, CouponsId,  Source,  UserId);
            return Ok(new { meg, a } );
        }
        /// <summary>
        /// 更新状态
        /// </summary>
        /// <param name="id">优惠券的ID</param>
        /// <param name="state"></param>
        /// <returns></returns>
        [HttpPut("Update")]
        public IActionResult Update(Guid id, int state)
        {
            var a = _home.Update(id, state);
            return Ok(a);
        }
        /// <summary>
        /// 按照券类型查询清单
        /// </summary>
        /// <param name="CouponId"></param>
        /// <returns></returns>
        [HttpGet("GetCouponId")]
        public IActionResult GetCouponId(Guid CouponId, int total, int page , int pageSize )
        {
            IList<CouponsModel> list = new List<CouponsModel>();
            list = _home.GetCouponId(CouponId, out total, page , pageSize);
            return Ok(new { Total = total, data = list });
        }
        /// <summary>
        /// 按照用户类型查询优惠券清单
        /// </summary>
        /// <param name="UserId"></param>
        /// <param name="total"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("GetUserId")]
        public IActionResult GetUserId(Guid UserId, int total, int page , int pageSize )
        {
            IList<CouponsModel> list = new List<CouponsModel>();
            list = _home.GetUserId(UserId, out total, page , pageSize );
            return Ok(new { Total = total, data = list });
        }
        /// <summary>
        /// 按照来源查询优惠券清单
        /// </summary>
        /// <param name="Source"></param>
        /// <param name="total"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("GetSource")]
        public IActionResult GetSource(string Source, int total, int page = 1, int pageSize = 10)
        {
            IList<CouponsModel> list = new List<CouponsModel>();
            list = _home.GetSource(Source, out total ,page,pageSize);
            return Ok(new { Total = total, data = list });
        }
        /// <summary>
        /// 按照身份查询优惠券清单
        /// </summary>
        /// <param name="State"></param>
        /// <param name="total"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("GetState")]
        public IActionResult GetState(int State, int total, int page = 1, int pageSize = 10)
        {
            IList<CouponsModel> list = new List<CouponsModel>();
            list = _home.GetState(State, out total, page , pageSize );
            return Ok(new { Total = total, data = list });
        }
    }
}